/**
 * @description: 加解密算法
 * @fileName: decrypt
 * @author: xsz
 * @date: 2022/4/14-10:13
 * @version: V1.0.0
 **/
const CryptoJS = require('crypto-js') // 引用AES源码js
const key = CryptoJS.enc.Utf8.parse('M7JpG_MNi3l=qWhA')// 十六位十六进制数作为密钥
const iv = CryptoJS.enc.Utf8.parse('Km2S=Vkq6WCB_WEs')// 十六位十六进制数作为密钥偏移量
const options = {
  iv: iv,
  mode: CryptoJS.mode.CBC,
  padding: CryptoJS.pad.Pkcs7
}
// 解密方法
function Decrypt(word) {
  if (!word) return
  const encryptedHexStr = CryptoJS.format.Hex.parse(word)
  const decrypt = CryptoJS.AES.decrypt(encryptedHexStr, key, options)
  return CryptoJS.enc.Utf8.stringify(decrypt)
}

// 加密方法
function Encrypt(word) {
  if (!word) return
  const encrypted = CryptoJS.AES.encrypt(JSON.stringify(word), key, options)
  return encrypted.ciphertext.toString()
}

export {
  Decrypt,
  Encrypt
}
